<template>
  <div class="container_order">
    <van-nav-bar title="新增订单" fixed @click-left="onClickLeft">
      <van-icon name="arrow-left" slot="left" color="#333" size="0.6rem" />
    </van-nav-bar>
    <van-cell-group class="count cod" @click="deliver" v-if="deliverVal">
      <div class="cod_box">
        <p>{{ faAddress }}</p>
        <div style="width:110px;text-align: right;">
          <van-tag
            color="#f2826a"
            v-if="deliverValArr.filter((item) => item == '需要提货').length"
            plain
            >提</van-tag
          >
          <van-tag
            color="#f2826a"
            v-if="deliverValArr.filter((item) => item == '需要装车').length"
            style="marginleft: 5px"
            plain
            >装</van-tag
          >
          <van-tag
            color="#f2826a"
            v-if="deliverValArr.filter((item) => item == '需要过磅').length"
            style="marginleft: 5px"
            plain
            >过磅</van-tag
          >
        </div>
      </div>
      <van-cell center :title="facount" />
    </van-cell-group>
    <van-cell-group v-else class="count_fist" @click="deliver">
      <van-cell center title="发货信息" />
      <van-cell center title="点击填写发货人地址信息" is-link />
    </van-cell-group>

    <van-cell-group class="count">
      <van-cell class="total" :title="`经停点信息`">
        <template #right-icon>
          <span class="addStopOrder" @click="addStop">+添加经停</span>
        </template>
      </van-cell>
    </van-cell-group>

    <van-cell-group
      class="count"
      v-for="(item, index) in stopOverList"
      :key="index"
    >
      <van-cell class="total" :title="`经停点 ${stopOverList.length - index}`">
        <template #right-icon>
          <span class="addStopOrder" @click="removeStop(index)">-删除经停</span>
        </template>
      </van-cell>
      <van-cell
        class="totaltitle"
        :title="item.shrpPeopleName == '' ? '经停地址' : item.shrpPeopleName"
        :label="
          item.shrpProvinceName != ''
            ? `${item.shrpProvinceName}-${item.shrpCityName}-${item.shrpAreaName} ${item.shrpDes}`
            : '点击填写经停地址信息'
        "
        @click="
          () => {
            $router.push(`/stopover?ind=${index}&kauserId=${query.kauserId}`);
          }
        "
        is-link
      />
      <van-cell
        title="货量"
        :value="
          item.kaGoodTypeSumInfo.kaWeightKg == ''
            ? '请填写'
            : `${item.kaGoodTypeSumInfo.kaQuantity}件-${item.kaGoodTypeSumInfo.kaWeightKg}kg-${item.kaGoodTypeSumInfo.kaVolume}m³`
        "
        @click="
          () => {
            $router.push(`/stopgoods?ind=${index}`);
          }
        "
      />
    </van-cell-group>

    <van-cell-group class="count cod" @click="receiving" v-if="receivingVal">
      <div class="cod_box">
        <p>{{ shouAddress }}</p>
        <div>
          <van-tag
            color="#f2826a"
            v-if="receivingValArr.filter((item) => item == '需要送货').length"
            plain
            >送</van-tag
          >
          <van-tag
            color="#f2826a"
            v-if="receivingValArr.filter((item) => item == '需要卸车').length"
            style="marginleft: 5px"
            plain
            >卸</van-tag
          >
        </div>
      </div>
      <van-cell center :title="shoucount" />
    </van-cell-group>

    <van-cell-group class="count" @click="receiving" v-else>
      <van-cell center title="收货地址" />
      <van-cell center title="点击填写收货人地址信息" is-link />
    </van-cell-group>

    <van-cell-group class="count" @click="onOver">
      <van-cell title="货物清单" is-link />
      <van-cell title="总件数" :value="number" />
      <van-cell title="总重量(公斤)" :value="KG" />
      <van-cell title="总体积(方)" :value="M3" />
    </van-cell-group>
    <van-cell-group class="count" @click="feedetails">
      <van-cell title="费用详情" is-link />
      <van-cell title="上游应收合计" :value="UpMoney" />
      <!-- <van-cell title="下游应付合计" :value="DownMoney" /> -->
    </van-cell-group>
    <van-cell-group class="count">
      <van-cell title="其他" />
      <van-cell
        title="付款方式"
        :value="paymentMony"
        is-link
        @click="payment"
      />
      <van-cell
        title="选择优惠券"
        :value="paymentLiner"
        is-link
        @click="showTypeLiner"
      />
      <!-- <van-field v-model="delivery" label="货物保价" placeholder="请输入" input-align="right" type="number" /> -->
      <van-field
        class="assure"
        v-model="delivery"
        type="digit"
        size="large"
        placeholder="请输入"
        input-align="right"
      >
        <template slot="label">
          <span class="custom-title">货物保价</span>
          <span class="custom-assure">（保费应收￥{{ kaInsuredPrice }}）</span>
        </template>
      </van-field>
      <van-cell
        title="发票类型"
        label="下单成功发票类型不可变更"
        label-class="lab"
        :value="invoice"
        is-link
        @click="invoiceclick"
      />
      <!-- <van-cell title="短信服务设置" :value="ShortMessage" is-link @click="sms" /> -->
      <!-- <van-cell
        title="查货人"
        @click="() => $router.push({path:'/check', query:query})"
        :value="check"
        is-link
      /> -->
      <van-field
        v-model="maks"
        label="备注"
        placeholder="请输入"
        input-align="right"
      />
    </van-cell-group>
    <div style="height: 57px"></div>
    <div class="buton">
      <van-button
        class="butonO"
        type="primary"
        size="large"
        @click="onClickLeft"
        >取消</van-button
      >
      <van-button class="butonT" type="primary" @click="onOK" size="large"
        >确定</van-button
      >
    </div>
    <van-action-sheet
      v-model="show"
      :description="lifalg ? '逾期未付款，暂不支持周期结算' : ''"
      title="付款方式"
    >
      <div class="content">
        <div class="box_added">
          <div class="checkSteper">
            <ul>
              <li
                :class="
                  checkArr.filter((item) => item == '现付').length
                    ? 'active'
                    : ''
                "
                @click="onclick('现付')"
              >
                现付
              </li>
              <li
                v-if="!lifalg"
                :class="
                  checkArr.filter((item) => item == '月结').length
                    ? 'active'
                    : ''
                "
                @click="onclick('月结')"
              >
                月结
              </li>
            </ul>
          </div>
        </div>
      </div>
    </van-action-sheet>
    <van-action-sheet
      v-model="invoiceshow"
      :actions="invoiceaction"
      cancel-text="取消"
      close-on-click-action
      @cancel="onCancel"
      @select="oninvoiceSelect"
    />
    <!-- <van-action-sheet
      v-model="invoiceshow"
      title="发票类型"
      description="下单成功发票类型不可变更，谨慎选择"
    >
      <div class="content">
        <div class="box_added">
          <div class="checkSteper">
            <ul>
              <div
                v-for="(item, index) in invoiceResTotalArr.treeData"
                :key="index"
              >
                <li
                  :class="indexs == index ? 'active' : ''"
                  @click="oninvoiceclick(item[0].remark, index, 0)"
                  v-if="item.length == 1"
                >
                  {{ item[0].remark }}
                </li>
                <li
                  :class="indexs == index ? 'active' : ''"
                  @click="oninvoiceclick('增值税发票', index, 0)"
                  v-else
                >
                  增值税发票
                </li>
              </div>
            </ul>
          </div>
        </div>
      </div>
      <div class="content" v-if="invoiceRes.length">
        <div class="box_added">
          <div class="checkSteper">
            <ul>
              <li
                v-for="(item, index) in invoiceRes"
                :key="index"
                :class="
                  invoiceResArr.filter((items) => items == item.taxPoint).length
                    ? 'active'
                    : ''
                "
                @click="oninvoicenive(index)"
              >
                {{ item.taxPoint }}%
              </li>
            </ul>
          </div>
        </div>
      </div>
    </van-action-sheet> -->
    <van-action-sheet
      v-model="showType"
      :actions="actions"
      cancel-text="取消"
      close-on-click-action
      @cancel="onCancel"
      @select="onSelect"
    />
    <!-- </van-popup> -->
  </div>
</template>

<script>
import Vue from "vue";
import { Tag, Toast, Dialog } from "vant";
import {
  selLottery,
  addOrder,
  getBdInvoiceConfig,
  getBdHTInvoiceConfig,
} from "@/api/add";
Vue.use(Dialog);
Vue.use(Tag);
Vue.use(Toast);
export default {
  data() {
    return {
      delivery: "",
      show: false,
      kaInsuredPrice: 0,
      checkArr: ["现付"],
      paymentMony: "现付",
      invoiceArr: [],
      invoice: "",
      invoicestate: null,
      invoiceshow: false,
      invoiceRes: [],
      invoiceResArr: [],
      invoiceResTotalArr: [],
      paymentLiner: "暂不使用优惠卷",
      showType: false,
      maks: "",
      actions: [{ name: "暂不使用优惠券", LotteryID: "" }],
      invoiceaction:[{ name: "暂无发票类型", invoiceId: "" }],
      query: {},
      shouAddress: "",
      faAddress: "",
      number: "请输入",
      shoucount: "",
      facount: "",
      KG: "请输入",
      M3: "请输入",
      check: "请输入",
      UpMoney: "请输入",
      DownMoney: "请输入",
      ShortMessage: "请配置",
      indexs: 0,
      receivingVal: null,
      deliverVal: null,
      lifalg: false,
      receivingValArr:
        JSON.parse(sessionStorage.getItem("receiving_checkArr")) || "",
      deliverValArr:
        JSON.parse(sessionStorage.getItem("deliver_checkArr")) || "",
      linerARr: [],
      stopOverList: [],
    };
  },
  watch: {
    maks(val) {
      sessionStorage.setItem("marsk", val);
    },
    delivery: {
      handler: function (newVal) {
        let val = newVal;
        this.kaInsuredPrice = Math.round(val * 0.003 * 100) / 100;
      },
    },
  },
  created() {
      let routers = this.$router.history.current.query.kaUserContractStatus;
      
      if (routers == 0 || routers == 1 || routers == 2) {
        // 如果有合同用户则重新获取发票类型
          getBdHTInvoiceConfig(
            this.$router.history.current.query.kauserId
          ).then((res) => {
            let resarr = []
            res.data.treeData.map(item=>{
              item.map(items=>{
                resarr.push({name:`${items.remark} ${items.taxPoint ? items.taxPoint + '%' : ""}`,invoiceId: items.invoiceId})
              })
            })
            if (JSON.parse(sessionStorage.getItem("invoice"))) {
              this.invoice = JSON.parse(sessionStorage.getItem("invoice")).name
            }else{
              this.invoice = resarr[0].name
              sessionStorage.setItem('invoice',JSON.stringify(resarr[0]))
            }
            this.invoiceaction = resarr
          });
      } else {
        getBdInvoiceConfig(this.$router.history.current.query.kauserId).then((res) => {
          let resarr = []
          res.data.treeData.map(item=>{
            item.map(items=>{
              resarr.push({name:`${items.remark}`,invoiceId: items.invoiceId})
            })
          })
          if (JSON.parse(sessionStorage.getItem("invoice"))) {
            this.invoice = JSON.parse(sessionStorage.getItem("invoice")).name
          }else{
             this.invoice = resarr[0].name
            sessionStorage.setItem('invoice',JSON.stringify(resarr[0]))
          }
          this.invoiceaction = resarr
        });
      }
    if (this.$router.history.current.query.blackType == 1) {
      this.lifalg = true;
    }
  },
  mounted() {
    // 获取路径带的用户ID
    this.query = this.$router.history.current.query;
    this.receivingVal = JSON.parse(sessionStorage.getItem("receiving"))
      ? JSON.parse(sessionStorage.getItem("receiving"))
      : null;
    if (this.receivingVal != null) {
      this.shoucount = `${this.receivingVal.CITYNAME} ${this.receivingVal.AREANAME} ${this.receivingVal.KaUabDes} `;
    }
    this.deliverVal = JSON.parse(sessionStorage.getItem("deliver"))
      ? JSON.parse(sessionStorage.getItem("deliver"))
      : null;
    if (this.deliverVal != null) {
      this.facount = `${this.deliverVal.CITYNAME} ${this.deliverVal.AREANAME} ${this.deliverVal.KaUabDes} `;
    }
    this.shouAddress = JSON.parse(sessionStorage.getItem("receiving"))
      ? `${JSON.parse(sessionStorage.getItem("receiving")).KaUabLinker}  ${
          JSON.parse(sessionStorage.getItem("receiving")).KaUabTel
        }`
      : "收货地址";
    this.faAddress = JSON.parse(sessionStorage.getItem("deliver"))
      ? `${JSON.parse(sessionStorage.getItem("deliver")).KaUabLinker} ${
          JSON.parse(sessionStorage.getItem("deliver")).KaUabTel
        }`
      : "发货地址";
    if (JSON.parse(sessionStorage.getItem("orderInfo"))) {
      let num = 0;
      let kgs = 0;
      let m3s = 0;
      if (JSON.parse(sessionStorage.getItem("orderInfo"))) {
        JSON.parse(sessionStorage.getItem("orderInfo")).map((item) => {
          num += Number(item.KaQuantity);
          kgs += Number(item.KaWeightKg);
          m3s += Number(item.KaVolume);
        });
        this.number = num;
        this.KG = kgs;
        this.M3 = m3s;
      }
    }

    if (JSON.parse(sessionStorage.getItem("feed"))) {
      let feed = JSON.parse(sessionStorage.getItem("feed"));
      this.UpMoney = 0;
      this.DownMoney = 0;
      if (feed.TabArr[0] == "人工报价") {
        console.log(111111)
        this.UpMoney += Number(feed.kaArPickUp);
        this.UpMoney += Number(feed.kaArSend);
        this.UpMoney += Number(feed.kaArFreight);
        this.DownMoney += Number(feed.carrierPrice);
        this.DownMoney += Number(feed.carrierPickUp);
        this.DownMoney += Number(feed.carrierSend);
      } else {
        this.UpMoney = feed.JPSmoney;
        this.DownMoney = feed.JPXmoney;
      }
    }

    if (JSON.parse(sessionStorage.getItem("message"))) {
      let message = JSON.parse(sessionStorage.getItem("message"));
      if (message.medalTit.length != 4) {
        this.ShortMessage = `${message.medalTit.substring(0, 8)}...`;
      } else {
        this.ShortMessage = "均不通知";
      }
    }

    if (JSON.parse(sessionStorage.getItem("check"))) {
      let check = JSON.parse(sessionStorage.getItem("check"));
      this.check = `${check.stockingGoodsMan} - ${check.stockingGoodsMobile}`;
    }

    if (sessionStorage.getItem("marsk")) {
      this.maks = sessionStorage.getItem("marsk");
    }

    selLottery(this.query.kauserId).then((res) => {
      console.log(res);
      this.linerARr = res.data;
      this.linerARr.map((item) => {
        this.actions.push({
          name: item.Coudescribe,
          LotteryID: item.LotteryID,
        });
      });
    });
    if (JSON.parse(sessionStorage.getItem("stopOverList"))) {
      this.stopOverList = JSON.parse(sessionStorage.getItem("stopOverList"));
    }
    sessionStorage.removeItem("stopListClick");
    if (!JSON.parse(sessionStorage.getItem("stopOverList"))) {
      sessionStorage.setItem("stopOverList", JSON.stringify(this.stopOverList));
    }
  },
  methods: {
    onCancel() {
      this.showType = false;
    },
    onClickLeft() {
      this.$router.back();
    },
    onshipper() {
      this.$router.push({
        path: "/shipperinfo",
        query: this.query,
      });
    },
    onclick(val) {
      this.checkArr = [];
      this.checkArr.push(val);
      this.paymentMony = this.checkArr[0];
      this.show = false;
    },
    // oninvoiceclick(val, index, ind) {
    //   this.indexs = index;
    //   this.invoiceArr = [];
    //   this.invoiceArr.push(val);
    //   this.invoice = this.invoiceArr[0];
    //   if (this.invoiceResTotalArr.treeData[index].length <= 1) {
    //     this.invoiceshow = false;
    //     this.invoicestate = this.invoiceResTotalArr.treeData[index][
    //       ind
    //     ].invoiceId;
    //     this.invoiceRes = [];
    //     this.invoiceResArr = [];
    //     sessionStorage.setItem("invoice", JSON.stringify(null));
    //     sessionStorage.setItem(
    //       "invoiceData",
    //       JSON.stringify([this.invoiceResTotalArr.treeData[index][0]])
    //     );
    //     sessionStorage.setItem("indexs", JSON.stringify(index));
    //   } else {
    //     this.invoiceRes = [];
    //     this.invoiceRes = this.invoiceResTotalArr.treeData[index];
    //     this.invoiceResArr = [
    //       this.invoiceResTotalArr.treeData[index][ind].taxPoint,
    //     ];
    //     this.invoicestate = this.invoiceResTotalArr.treeData[index][
    //       ind
    //     ].invoiceId;
    //     this.invoice = `专票,税点${this.invoiceResTotalArr.treeData[index][ind].taxPoint}%`;
    //     sessionStorage.setItem(
    //       "invoice",
    //       JSON.stringify(this.invoiceResTotalArr.treeData[index][ind])
    //     );
    //     sessionStorage.setItem(
    //       "invoiceData",
    //       JSON.stringify(this.invoiceResTotalArr.treeData[index])
    //     );
    //   }
    // },
    // oninvoicenive(ind) {
    //   this.invoicestate = this.invoiceRes[ind].invoiceId;
    //   this.invoiceResArr = [this.invoiceRes[ind].taxPoint];
    //   this.invoice = `专票,税点${this.invoiceRes[ind].taxPoint}%`;
    //   this.invoiceshow = false;
    //   sessionStorage.setItem("invoice", JSON.stringify(this.invoiceRes[ind]));
    // },
    sms() {
      this.$router.push({
        path: "/sms",
        query: this.query,
      });
    },
    oninvoiceSelect(val){
      this.invoice = val.name
      sessionStorage.setItem('invoice',JSON.stringify(val))
    },
    onSelect(val) {
      console.log(val);
      this.paymentLiner = val.name;
      this.paymentLinerID = val.LotteryID;
    },
    onOver() {
      this.$router.push({
        path: "/goods",
        query: this.query,
      });
    },
    feedetails() {
      if (
        !JSON.parse(sessionStorage.getItem("deliver")) ||
        !JSON.parse(sessionStorage.getItem("receiving"))
      ) {
        Toast.fail("请将发货地址或收货地址信息补全在进行填写");
      } else {
        this.$router.push({
          path: "/feedetails",
          query: this.query,
        });
      }
    },
    receiving() {
      this.$router.push({
        path: "/receiving",
        query: this.query,
      });
    },
    deliver() {
      this.$router.push({
        path: "/deliver",
        query: this.query,
      });
    },
    payment() {
      this.show = !this.show;
    },
    invoiceclick() {
      this.invoiceshow = !this.invoiceshow;
    },
    showTypeLiner() {
      this.showType = true;
    },
    onOK() {
      if (!JSON.parse(sessionStorage.getItem("deliver"))) {
        Toast.fail("发货信息不能为空");
        return false;
      }
      if (!JSON.parse(sessionStorage.getItem("orderInfo"))) {
        Toast.fail("货物信息不能为空");
        return false;
      }
      if (this.stopOverList.length == 1) {
        let str = "【";
        if (
          !this.stopOverList[0].kaGoodsTypeList.length &&
          this.stopOverList[0].shrpAreaCode == ""
        ) {
          this.stopOverList = [];
          this.getorder();
        } else {
          if (
            this.stopOverList[0].kaGoodsTypeList.length &&
            this.stopOverList[0].shrpAreaCode
          ) {
            this.getorder();
          } else {
            if (!this.stopOverList[0].kaGoodsTypeList.length) {
              str += "货量 ";
            }
            if (this.stopOverList[0].shrpAreaCode == "") {
              str += "经停地址";
            }
            str += "】";
            Dialog.confirm({
              title: "确认提示",
              showCancelButton: true,
              confirmButtonText: "继续下单",
              cancelButtonText: "确认填写",
              message:
                "经停1: " +
                str +
                "缺失；请填写完毕再下单，否则系统将自动删除此类经停！",
            })
              .then(() => {
                // on confirm
                this.getorder();
              })
              .catch(() => {
                // on cancel
                return;
              });
          }
        }
      } else {
        let strhtml = "";
        this.stopOverList.forEach((item, index) => {
          let str = "";
          console.log(item);
          if (!item.kaGoodsTypeList.length) {
            str += "货量 ";
          }
          if (!item.shrpAreaCode) {
            str += "经停地址";
          }
          if (str.length) {
            strhtml += `经停${index + 1}：【${str}】缺失；<br/>`;
          }
        });
        strhtml += "";
        if (strhtml.length) {
          Dialog.confirm({
            title: "确认提示",
            showCancelButton: true,
            confirmButtonText: "继续下单",
            cancelButtonText: "确认填写",
            message: `<div style='text-align:left'>${strhtml}</div>请填写完毕再下单，否则系统将自动删除此类经停！`,
          })
            .then(() => {
              // on confirm
              this.getorder();
            })
            .catch(() => {
              // on cancel
              return;
            });
        } else {
          this.getorder();
        }
      }
    },
    getorder() {
      console.log( JSON.parse(sessionStorage.getItem("deliver_checkArr")).filter(
          (item) => item == "需要提货"
        ).length,1111)
      let receiving = JSON.parse(sessionStorage.getItem("receiving"));
      let deliver = JSON.parse(sessionStorage.getItem("deliver"));
      let feed = JSON.parse(sessionStorage.getItem("feed"));
      let kauserinfo = JSON.parse(localStorage.getItem("kauserinfo"));
      let payment = 0;
      if (this.paymentMony == "现结") {
        payment = 0;
      } else if (this.paymentMony == "月结") {
        payment = 1;
      }
      let list = {}
      Object.assign(list, JSON.parse(sessionStorage.getItem("feed"))); // 合并费用详情的字段
      Object.assign(list, JSON.parse(sessionStorage.getItem("message"))); // 合并短信配置的字段
      Object.assign(list, JSON.parse(sessionStorage.getItem("check"))); // 合并查货人的字段
      Object.assign(list, {
        invoiceConfigId: JSON.parse(sessionStorage.getItem('invoice')).invoiceId, // 发票类型
        pushPlatform: feed && feed.PushPlatform ? feed.PushPlatform : 0, // 推送平台
        shrpPeopleName: deliver.KaUabLinker, // 发货人姓名
        shrpPeopleTel: deliver.KaUabTel, // 发货人电话
        shrpProvinceCode: deliver.KaUabProvince, //发货省code
        shrpCityCode: deliver.KaUabCity, // 发货市code
        shrpAreaCode: deliver.KaUabArea, // 发货区code
        shortDeptId: deliver.shortDeptId || "", // 营业网点id
        shortStationId: deliver.shortStationId || "", // 站点id
        shortDeptName: deliver.shortDeptName || "", // 营业网点名称
        shortStationName: deliver.shortStationName || "", // 站点名称
        shrpDes: `${deliver.KaUabDes}`, // 发货地详细地址
        cneePeopleName: receiving ? receiving.KaUabLinker : "", // 收货人姓名
        cneePeopleTel: receiving ? receiving.KaUabTel : "", // 收货人电话
        cneeProvinceCode: receiving ? receiving.KaUabProvince : "", // 收货省code
        cneeCityCode: receiving ? receiving.KaUabCity : "", // 收货市code
        cneeAreaCode: receiving ? receiving.KaUabArea : "", // 收货区code
        cneeDes: receiving ? `${receiving.KaUabDes}` : "", // 收货地详细地址
        shrpLongitude: deliver ? deliver.shrpLongitude : "", // 发货经度
        shrpLatitude: deliver ? deliver.shrpLatitude : "", // 发维度
        cneeLongitude: receiving ? receiving.cneeLongitude : "", // 收货经度
        cneeLatitude: receiving ? receiving.cneeLatitude : "", // 收货维度
        stopOverList: this.stopOverList.reverse(),

        userContractId: this.$router.history.current.query.kaUserContractId,
        kaUserContractStatus: this.$router.history.current.query
          .kaUserContractStatus,
        // invoiceConfigId:this.$router.history.current.query.invoiceConfigId,

        receivInfo: deliver, // 发货地址集合
        sendInfo: receiving ? receiving : "", // 收货地址集合
        kaShprAddressbookId: deliver ? deliver.KaUserAddressbookId : "", // 发货人地址簿ID
        kaCneeAddressbookId: receiving ? receiving.KaUserAddressbookId : "", // 提货人地址薄ID
        kaGoodsTypeList: JSON.parse(sessionStorage.getItem("orderInfo")), // 货物清单
        kaGoodsTypeListStr: sessionStorage.getItem("orderInfo"), // 货物清单json串
        kaQuantity: this.number, // 件数
        kaVolume: this.M3, // 体积
        kaWeightKg: this.KG, // 重量
        kaSource: 7, // 订单来源
        kaUserId: this.query.kauserId, // ka用户id
        kaGoodValues: this.delivery, // 保价金额

        estimatedPrescription: "", // 预估时效
        isPickUpOperate: 0,
        kaAppointmentEnd: deliver.KaAppointmentEnd, // 预约提货时间止
        kaAppointmentStart: deliver.KaAppointmentStart, // 预约提货时间起
        kaPayment: payment, // 0现付 1现付月结 2现付半月结 3现付周月结
        kaRemarks: this.maks, // 备注
        // KaTotalFreight: '', // 使用优惠券前的总费用
        // KaTotalPrice: '', // 总费用
        agencyId: this.query.kauserId, // 承运商id
        companyId: kauserinfo.kaUserId, //公司id
        dayText: "今天",
        employeeId: kauserinfo.employeeId, // 员工id
        isLoading: JSON.parse(
          sessionStorage.getItem("deliver_checkArr")
        ).filter((item) => item == "需要装车").length, // 是否装车
        isUnLoading: JSON.parse(sessionStorage.getItem("receiving_checkArr"))
          ? JSON.parse(sessionStorage.getItem("receiving_checkArr")).filter(
              (item) => item == "需要卸车"
            ).length
          : "", // 是否卸货车
        kaDelivery: JSON.parse(sessionStorage.getItem("receiving_checkArr"))
          ? JSON.parse(sessionStorage.getItem("receiving_checkArr")).filter(
              (item) => item == "需要送货"
            ).length
          : "", // 是否送货
        kaPickup: JSON.parse(sessionStorage.getItem("deliver_checkArr")).filter(
          (item) => item == "需要提货"
        ).length, // 是否提货
        overPump: JSON.parse(sessionStorage.getItem("deliver_checkArr"))
          ? JSON.parse(sessionStorage.getItem("deliver_checkArr")).filter(
              (item) => item == "需要过磅"
            ).length
          : "", // 是否过磅
        jpLineExist: "",
        kaInputUserId: JSON.parse(localStorage.getItem("userInfo")).userId, // 录入人id
        kaInputUserName: JSON.parse(localStorage.getItem("userInfo")).userName, // 录入人名称
        proposalDiscount: null,
        lotteryId: this.paymentLinerID,
        // pushPlatform: '', // 推送至平台
        // PushPlatformPc: '' // 精拼报价/人工报价
      });
      if (JSON.parse(sessionStorage.getItem("feed"))) {
        list.kaSysPriceRecordWrapper = {
          remark: JSON.parse(sessionStorage.getItem("feed")).remark,
          upSysSendFee: JSON.parse(sessionStorage.getItem("feed")).kaArSend, // 上游系统送货费（含税含利润）
          upSysLineFee: JSON.parse(sessionStorage.getItem("feed")).kaArFreight, // 上游系统干线费（含税含利润）
          upSysPickUpFee: JSON.parse(sessionStorage.getItem("feed")).kaArPickUp, // 上游系统提货费（含税含利润）

          downSysSendFee: JSON.parse(sessionStorage.getItem("feed"))
            .carrierSend, // 下游系统送货费（含税含利润）
          downSysLineFee: JSON.parse(sessionStorage.getItem("feed"))
            .carrierPrice, // 下游系统干线费（含税含利润）
          downSysPickUpFee: JSON.parse(sessionStorage.getItem("feed"))
            .carrierPickUp, // 下游系统提货费（含税含利润）
        };
      }
      addOrder(list).then((res) => {
        console.log(res);
        Toast.success("下单成功");
        sessionStorage.clear();
        setTimeout(() => {
          this.$router.push({
            path: "/",
          });
        }, 500);
      });
    },
    addStop(e) {
      this.stopOverList.unshift({
        kaGoodsTypeList: [],
        kaGoodTypeSumInfo: {
          dataSum: "", //总计
          kaQuantity: "", //件数
          kaVolume: "", // 体积
          kaWeightKg: "", // 重量
        },
        shrpPeopleName: "",
        shrpPeopleTel: "",
        shrpProvinceCode: "",
        shrpProvinceName: "",
        paymentLinerID: "",
        shrpCityCode: "",
        shrpCityName: "",
        shrpAreaCode: "",
        shrpAreaName: "",
        shrpDes: "",
        kaUserId: "",
      });
      sessionStorage.setItem("stopOverList", JSON.stringify(this.stopOverList));
    },
    removeStop(ind) {
      this.stopOverList.splice(ind, 1);
      sessionStorage.setItem("stopOverList", JSON.stringify(this.stopOverList));
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.assure .van-field__label {
  flex: 7;
}
.custom-assure {
  color: #ff6540;
}
.container_order {
  padding: 54px 18px 10px 18px;
  box-sizing: border-box;
  overflow: scroll;
  // font-size: 12px;
  width: 100%;
  height: 100%;
}
.count {
  margin-top: 10px;
  background: #ffffff;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
  border-radius: 5px;
}
.count_fist {
  background: #ffffff;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
  border-radius: 5px;
}
.buton {
  padding: 8px 16px;
  box-sizing: border-box;
  display: flex;
  border-radius: 5px;
  justify-content: space-around;
  background: #fff;
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  .butonO {
    background: #fff;
    width: 328px;
    height: 44px;
    border: 1px solid #f18d00;
    border-radius: 5px;
    color: #f18d00;
  }
  .butonT {
    background: #f18d00;
    width: 328px;
    height: 44px;
    margin-left: 10px;
    border-radius: 5px;
    border: 1px solid #f18d00;
  }
}
.box_added {
  box-sizing: border-box;
  background: #fff;
  margin-top: 10px;
  .checkSteper {
    padding: 10px 10px;
    box-sizing: border-box;
    font-size: 15px;
    background: #fff;
    box-sizing: border-box;
    ul {
      display: flex;
      li {
        border: 1px solid #f3f3f3;
        color: #666666;
        // width: 100px;
        padding: 0 10px;
        box-sizing: border-box;
        height: 30px;
        text-align: center;
        line-height: 30px;
        margin-right: 18px;
        background: #f3f3f3;
        border-radius: 4px;
      }
      .active {
        border: 0.5px solid #f18d00;
        color: #f18d00;
        background: #fffaf2;
      }
    }
  }
}
.cod {
  .cod_box {
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    padding: 15px;
    box-sizing: border-box;
    border-bottom: 1px solid #ebedf0;
  }
}
.lab {
  color: red;
  white-space: nowrap;
}
.addStopOrder {
  color: #f18d00;
  font-weight: bold;
  font-size: 13px;
}
.totaltitle {
  display: flex;
  align-items: center;
}
</style>